Builder

A validated string builder, integrated with an EntryChecker builder

Author

fzzyhmstrs

Since

0.2.0

Parameters

defaultValue

the default String value

Samples

import me.fzzyhmstrs.fzzy_config.util.AllowableIdentifiers
import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.util.ValidationResult
import me.fzzyhmstrs.fzzy_config.validation.collection.ValidatedList
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedRegistryType
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedTagKey
import me.fzzyhmstrs.fzzy_config.validation.misc.*
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedColor.Companion.validatedColor
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedInt
import net.minecraft.item.Items
import net.minecraft.item.SwordItem
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
import java.awt.Color
import java.util.function.Function

fun main() { 
   //sampleStart 
   //example validated string. This is built using the Builder, which is typically recommended except in special circumstances
//this string requires that lowercase chicken be included in the string
val validatedString = ValidatedString.Builder("chickenfrog")
    .both { s, _ -> ValidationResult.predicated(s, s.contains("chicken"), "String must contain the lowercase word 'chicken'.") }
    .withCorrector()
    .both { s, _ ->
        if(s.contains("chicken")) {
            ValidationResult.success(s)
        } else {
            if(s.contains("chicken", true)) {
                val s2 = s.replace(Regex("(?i)chicken"), "chicken")
                ValidationResult.error(s2, "'chicken' needs to be lowercase in the string")
            } else {
                ValidationResult.error(s, "String must contain the lowercase word 'chicken'")
            }
        }
    }
    .build()

//string validated with regex. provides entry correction in the form of stripping invalid characters from the input string, leaving only the valid regex matching sections
//the regex provided in this example matches to Uppercase characters. AbCdE would fail validation, and would correct to ACE.
val regexString = ValidatedString("ABCDE", "\\p{Lu}")

//Unbounded validated string. Any valid string will be allowed
val unboundedString = ValidatedString("hamsters")

//Empty validated string. Any valid string will be allowed, and the default value is ""
val emptyString = ValidatedString()

//fields and sections have lang keys based on their "location" in the Config class graph.
//Lange key composition is as follows
//1. the namespace of the config id: (my_mod)
//2. the path of the config id: (my_mod.my_config)
//3. any parent ConfigSection field names as declared in-code: (my_mod.my_config.subSection)
//4. the setting field name as declared in-code: (my_mod.my_config.subSection.fieldName)
val fieldLang = """
{
    "_comment1": "the lang for an example 'fieldName' setting in a config inside section 'subSection'",
    "my_mod.my_config.subSection.fieldName": "Very Important Setting",
    "my_mod.my_config.subSection.fieldName.desc": "This very important setting is used in this very important way."
}
""" 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(defaultValue: String)

Functions

Link copied to clipboard
fun both(predicate: Predicate<String>, errorMsg: String = "Problem validating Entry!"): ValidatedString.Builder
Link copied to clipboard
Link copied to clipboard
fun strong(predicate: Predicate<String>, errorMsg: String = "Problem validating Entry!"): ValidatedString.Builder
Link copied to clipboard
fun weak(predicate: Predicate<String>, errorMsg: String = "Problem validating Entry!"): ValidatedString.Builder